/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package embeddedpaint.model.feature;

import embeddedpaint.model.layers.LayerManager;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;

public abstract class AImageTool extends Observable implements ActionListener
{
    private static final boolean M_DEFAULT_IS_TOGGLE_BUTTON         = false;
    private static final boolean M_DEFAULT_ENABLE                   = true;
    private static final boolean M_DEFAULT_ACTIF                    = false;
    private static final String  M_ERROR_MESSAGE_IMAGE_NOT_LOADED   = "The tool icon image can't be loaded : ";
    
    protected LayerManager       m_imageManager;
    protected JFrame             m_application;
    protected boolean            m_enable;
    protected boolean            m_actif;

    public    abstract String getLabel ();
    
    protected abstract String getIconName ();

    public AImageTool (LayerManager imageManager, JFrame application)
    {
        this.m_application  = application;
        this.m_imageManager = imageManager;
        
        this.m_enable       = M_DEFAULT_ENABLE;
        this.m_actif        = M_DEFAULT_ACTIF;
    }

    public boolean isM_enable ()
    {
        return m_enable;
    }

    public ImageIcon getIcon ()
    {
        try
        {
            Image m_completeImage = ImageIO.read(new File(getIconName()));
            return new ImageIcon(m_completeImage);
        }
        catch (IOException ex)
        {
            System.err.println(M_ERROR_MESSAGE_IMAGE_NOT_LOADED + getIconName());
        }
        return null;
    }

    public boolean isToggleButton ()
    {
        return M_DEFAULT_IS_TOGGLE_BUTTON;
    }

    public void updateObservers ()
    {
        this.setChanged();
        
        this.notifyObservers();
    }

    public void dispose ()
    {
        // Can be override
    }

    public boolean isActif ()
    {
        return this.m_actif;
    }
}
